package com.yff.gateway.config;

import org.springframework.cloud.gateway.filter.ratelimit.KeyResolver;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import reactor.core.publisher.Mono;

/**
 * 限流规则配置类
 */

@Configuration
public class KeyResolverConfiguration {

    @Bean
    public KeyResolver pathKeyResolver()
    {
        return exchange -> Mono.just(exchange.getRequest().getURI().getPath());
    }

   /* @Bean
    public KeyResolver ipKeyResolver()
    {
        return exchange -> Mono.just(exchange.getRequest().getRemoteAddress().getHostName());
    }*/

   /* @Bean(name = "parameterKeyResolver")
    public KeyResolver parameterKeyResolver()
    {
        return exchange -> Mono.just(exchange.getRequest().getQueryParams().getFirst("userId"));
    }*/
}
